const DB = require('../../lib/DB')

module.exports = async function (ctx, next) {
    // 响应 [药品名称，编号，数量]
    const medicine_lib = await (await DB.models.medicine_lib.findAll({
        attributes: ['medicine_name', 'id', 'amount', 'sort_id', 'unit_price', 'dose'], include: {
            model: DB.models.dose,
            as: 'dose_dose'
        }
    })).map(e => {
        return {
            text: e.medicine_name,
            value: e.id,
            amount: e.amount,
            sort_id: e.sort_id,
            unit_price: e.unit_price,
            dose: e.dose_dose,
        }
    })
    ctx.body = medicine_lib;
    await next();
}